API Documentation
Public Member Functions | List of all members
nkTasks::Scheduler Class Referencefinal

Allows to automate task submission to a set of threads. More...

Public Member Functions

 Scheduler (size_t threadCount=0)
 
 ~Scheduler ()
 
size_t getThreadCount () const
 
ThreadgetThread (size_t index) const
 
void addTask (Task *task)
 
void resolveTask (Task *task)
 
void checkEndedTasks ()
 
void joinAllThreads ()
 
void resizeForThreadCount (size_t threadCount)
 

Detailed Description

Allows to automate task submission to a set of threads.

Aim is to schedule work and let it be distributed as smoothly as possible.

Constructor & Destructor Documentation

◆ Scheduler()

nkTasks::Scheduler::Scheduler ( size_t  threadCount = 0)

Constructor.

Parameters
threadCountThe number of thread wanted to populate the scheduler's pool. If 0, the scheduler will choose a plausible thead count itself.
Remarks
A plausible count for the scheduler will depend on the core count of target machine.

◆ ~Scheduler()

nkTasks::Scheduler::~Scheduler ( )

Destructor.

Member Function Documentation

◆ getThreadCount()

size_t nkTasks::Scheduler::getThreadCount ( ) const
Returns
The number of thread in thie scheduler's pool.

◆ getThread()

Thread* nkTasks::Scheduler::getThread ( size_t  index) const
Parameters
indexThe index in the pool of wanted thread.
Returns
The thread at given index if available, nullptr if unavailable.

◆ addTask()

void nkTasks::Scheduler::addTask ( Task task)

Submit a task to the scheduler.

Parameters
taskTask to submit.

◆ resolveTask()

void nkTasks::Scheduler::resolveTask ( Task task)

Allows to mark a task as resolved and trigger its post execution callbacks.

Parameters
taskThe task to resolve.
Remarks
Called by the threads in scheduler's pool. In theory, this function should not be called by external code.

◆ checkEndedTasks()

void nkTasks::Scheduler::checkEndedTasks ( )

Ticking function for execution. This should be called within the main thread, the one owning the scheduler and submitting work. Once a thread has finished processing a task, it will mark it as resolved and enqueue it for resolving within the scheduler. This function has to be called to fully resolve tasks that have been marked as resolved from the work thread.

◆ joinAllThreads()

void nkTasks::Scheduler::joinAllThreads ( )

Allows to join all threads of the scheduler.

◆ resizeForThreadCount()

void nkTasks::Scheduler::resizeForThreadCount ( size_t  threadCount)

Allows to change the number of threads constituting this scheduler's thread pool.

Parameters
threadCountThe number of threads that should constitute the pool.

The documentation for this class was generated from the following file: